feat: add default fetch handler export for server build#14794
feat: add default fetch handler export for server build#14794edmundhung wants to merge 1 commit intoremix-run:devfrom
Conversation
🦋 Changeset detectedLatest commit: 4c150ee The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @edmundhung, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
| import { env } from "cloudflare:workers"; | ||
| import type { Route } from "./+types/env"; | ||
| export function loader({ context }: Route.LoaderArgs) { | ||
| return { message: context.cloudflare.env.VALUE_FROM_CLOUDFLARE }; | ||
| export function loader() { | ||
| return { message: env.VALUE_FROM_CLOUDFLARE }; |
There was a problem hiding this comment.
We are using the importable env from the runtime module as the default fetch handler is runtime agnostic.
There is no context being passed through.
ab3b854 to
c7df6c3
Compare
c7df6c3 to
4c150ee
Compare
Hey! It's me again 👋🏼
I've been working on improving the Cloudflare Workers setup for React Router and am wondering if there is a way to remove some of the boilerplates. Right now, Cloudflare users need a worker entry file that essentially just calls
createRequestHandlerand re-exports it as a{ fetch }handler.I noticed the new RSC entries already ship uncompiled source files as package exports (
./config/default-rsc-entries/*) that get built by Vite, so I followed the same pattern here. This adds@react-router/dev/config/default-fetch-handlerwith about 12 lines that wrapcreateRequestHandlerwith the server build. Cloudflare users can then point theirmaindirectly at this export and skip the worker entry file entirely.I'll be honest though: Cloudflare is really the main beneficiary here. It's totally fine to close if this doesn't feel worth maintaining.